<template>
  <view>
    <!-- 抄送  该页面以反馈表的数据作为card内容-->
    <view class="card" v-for="item in feekbackList" :key="item.id" >
      <!-- :extra="item.taskStat==='0'?'未读':'已读'" -->
      <uni-card :title="item.confTitle" :extra="item.confDate">
        <view class="uni-body">任务：{{item.confContent}}</view>
        <view class="uni-body">负责人：{{item.nickName}}</view>
         <view class="uni-body">时间：{{item.recordTime}}</view>
        <view class="uni-body">我的反馈：{{item.feedBack? item.feedBack:'未反馈'}}</view>
        <view class="uni-body">
          审批状态：{{item.feedBackStat==='1'?'已通过':item.feedBackStat==='2'?'已退回':item.feedBackStat==='3'?'已取消':'未审批'}}
        </view>
        <view class="uni-body">审批备注：{{item.reply? item.reply:'无'}}</view>
        <view class="uni-body">
          <image v-if="item.fileImg" v-for="(i,index) in item.fileImg" :key="index"
            style="width: 200rpx; height: 200rpx; background-color: #eeeeee;" mode="scaleToFill" :src="i"
            @click="preview(item.fileImg)"></image>
        </view>
      </uni-card>
    </view>
  </view>
</template>

<script>
  import { listConference, getConference, delConference, addConference, updateConference,getRecord,getRecordName } from "@/api/system/conference";
  import config from '@/config'
  export default {
    data() {
      return {
        // 反馈列表
        feekbackList: [],
        // 查询会议表的参数
        queryParams: {
          // pageNum: 1,
          // pageSize: 10,
        },
        nickName: this.$store.state.user.nickname, //中文名
        userName: this.$store.state.user.name //用户名英文
      }
    },
    onReady() {
      this.getList()
    },
    methods: {
      async getList() {
        if (this.userName !== 'admin') {
          // console.log('不是admin账号，正常赋值名字查询');
          this.queryParams.ccName = this.nickName
        }
        //先查抄送人是自己的会议
       const confRes=await listConference(this.queryParams)
        // console.log(confRes)
        //利用map循环取出当前抄送人id的存到数组里  
        const ccNameList = confRes.rows.map(item => {
          return item
        })
        //  console.log(ccNameList);
        // 用抄送人查会议表得到id去查反馈表的confNo参数
        await Promise.all(
          ccNameList.map(async (ccNameItem) => {
            const {rows} = await getRecord(ccNameItem.id)
            // console.log(rows);
            this.feekbackList = [...this.feekbackList, ...rows]     
            return this.feekbackList
          })
        )
        this.feekbackList.forEach(item=>{
          if(item.fileImg){
            // console.log('有图')
            if(item.fileImg.indexOf(',')===-1){
              item.fileImg=[item.fileImg]
            }else{
               item.fileImg= item.fileImg.split(',')
            }
            item.fileImg=this.addFirst(config.baseUrl,item.fileImg)
          }
        })
        // console.log(this.feekbackList)
          // 判断反馈列表的会议号和会议表的id是否一致，相同就用$set方法动态添加属性
              this.feekbackList.filter(item=>ccNameList.some(ccitem=>{
                if(item.confNo===ccitem.id){
                   this.$set(item,"confDate",ccitem.confDate)
                   this.$set(item,"confTitle",ccitem.confTitle)
                   this.$set(item,"confContent",ccitem.confContent)
                   this.$set(item,"nickName",ccitem.nickName)
                   this.$set(item,"ccName",ccitem.ccName)
                   this.$set(item,"taskStat",ccitem.taskStat)
                }
                }))
                this.$_.orderBy(this.feekbackList,['recordTime'])
       
      },
      // pre   要添加的前缀  paramsList   要加前缀的数组
      addFirst(pre, paramsList) {
        let arr = [];

        for (let i = 0; i < paramsList.length; i++) {
          arr.push(pre + paramsList[i]);
        }
        return arr;
      },
      preview(imgurl) {
        // console.log(imgurl)
        uni.previewImage({
          urls: imgurl, //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
        })
      },



    }
  }
</script>
<style lang="less" scoped>
  .btn {
    margin-top: 15rpx;
    text-align: right;
  }
</style>